import 'package:flutter/material.dart';
import 'package:hospitable_rental/pages/home/search/room_item.dart';
import 'package:hospitable_rental/pages/home/search/room_item_widget.dart';
import 'package:hospitable_rental/routes/routes.dart';
import 'package:hospitable_rental/viewmodels/filter_bar_viewmodel.dart';
import 'package:hospitable_rental/widgets/filter_bar/fliter_drawer.dart';
import 'package:hospitable_rental/widgets/filter_bar/index.dart';
import 'package:hospitable_rental/widgets/search_bar/index.dart';
import 'package:provider/provider.dart';

class SearchIndex extends StatelessWidget {
  final List<RoomItem> dataList;

  const SearchIndex({
    Key? key,
    this.dataList = roomItemList,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      endDrawerEnableOpenDragGesture: false,
      endDrawer: FliterDrawer(
        onSubmit: () {
          var result = context.read<FilterBarViewModel>().result;
          print(
              "${result.areaId} - ${result.rentTypeId} - ${result.priceId} - ${result.moreIds.toString()}");
        },
      ),
      appBar: AppBar(
        actions: [Container()],
        elevation: 0,
        title: SearchBar(
          showLocation: true,
          showMap: true,
          onSearch: () => Navigator.of(context).pushNamed(Routes.notFound),
        ),
        backgroundColor: Colors.white,
      ),
      body: Column(
        children: [
          Container(
            height: 44.0,
            child: FilterBar(
              onChanged: (result) {
                print(
                    "${result.areaId} - ${result.rentTypeId} - ${result.priceId} - ${result.moreIds.toString()}");
              },
            ),
          ),
          Expanded(
            child: ListView.builder(
              itemCount: dataList.length,
              itemBuilder: _itemBuilder,
            ),
          )
        ],
      ),
    );
  }

  Widget _itemBuilder(BuildContext context, int index) {
    return RoomItemWidget(dataList[index]);
  }
}
